/**
 * Created by Administrator on 2015/6/8.
 */
'use strict';

var mysql = require('../common/mysql.js');
var M = require('./index.js');
var F = require('../common/function');

//活动步骤实体类
function activityStep(actStep) {
    this.set(actStep);
}

activityStep.prototype.get = function *(stepid) {
    if (stepid && stepid > 0) {
        let result = yield mysql.queryOne('SELECT mas.* FROM mh_activity_step mas where mas.asid=?', [stepid]);
        if (result && result.length) {
            this.set(result);
        }
    }
    return this.stepInfo;
};

activityStep.prototype.save = function (stepInfo) {
    if (stepInfo.stepid > 0) {//更新活动步骤规则
    }
}
activityStep.prototype.set = function (stepInfo) {
    this.stepInfo = {
        stepid: stepInfo['stepid'] || 0,
        actid: stepInfo['actid'] || 0,
        title: stepInfo['title'] || '',
        detail: stepInfo['detail'] || null,
        rule: stepInfo['rule'] || '',
        status: stepInfo['status'] || 0,
        sorder: stepInfo['sorder'] || 0,
        entity: stepInfo['entity'] || '',
        errormsg: stepInfo['errormsg'] || ''
    };
    return M.returnData(0, '', this.stepInfo);
};

activityStep.prototype.delete = function *() {
    if (this.stepInfo['stepid'] && this.stepInfo['stepid'] > 0) {
        let result = yield mysql.query('update mh_activity_step set status=0 where stepid=?', [this.stepid]);
        if (result.affectedRows == 0) {
            return M.returnData(1, '删除失败');
        }
        else {
            return M.returnData(0, '删除成功');
        }
    } else {
        return M.returnData(1, '参数无效');
    }
};


exports.activityStep = activityStep;